package com.xj.center.manager.api;

import com.alibaba.fastjson.JSONObject;
import com.xj.center.manager.service.DriverService;
import com.xj.center.manager.service.StatusService;
import com.xj.common.bean.R;
import com.xj.common.bean.constant.Common;
import com.xj.common.dto.DriverDto;
import com.xj.common.model.Driver;
import com.xj.common.utils.JsonPaseUtil;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.Map;

/**
 * 实时状态数据接口
 * @author wsp
 *
 */
@RestController
@RequestMapping(value = Common.Service.IE_MANAGER_STATUS)
public class StatusAPI {

	@Resource
	private StatusService statusService;

	@RequestMapping(value = Common.Service.IE_MANAGER_STATUS_DRIVER,method = RequestMethod.POST,produces = "application/json;charset=UTF-8")
	@CrossOrigin
	public R<Map<Long, String>> driverStatus(
			@RequestBody JSONObject jsonParam
			) throws IOException{

		try {
			Driver driver = JsonPaseUtil.JSONStrToObj(jsonParam.toJSONString(), Driver.class);
			DriverDto driverDto = new DriverDto();

			Map<Long, String> statuses = statusService.driver(driverDto.convert(driver));
			return R.ok(statuses);
		} catch (Exception e) {
			return R.fail(e.getMessage());
		}
	}

}